package com.zhangyu.shadow.repair.delegate.history;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhangyu.shadow.repair.R;

import java.util.List;

/**
 * @author zhangyu
 * @date 2018/12/4
 */

public class MaintainTypeAdapter extends BaseQuickAdapter<MaintainType, BaseViewHolder> {
    private List<String> mMaintainTypes;

    public MaintainTypeAdapter(int layoutResId,
                               List<String> maintainTypes,
                               @Nullable List<MaintainType> data) {
        super(layoutResId, data);
        mMaintainTypes = maintainTypes;
    }

    @Override
    protected void convert(BaseViewHolder helper, final MaintainType item) {
        helper.setText(R.id.cb, item.getName());
        helper.setChecked(R.id.cb, item.isCheck());
        helper.getView(R.id.cb).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.isCheck()) {
                    mMaintainTypes.remove(item.getName());
                } else {
                    mMaintainTypes.add(item.getName());
                }
                item.setCheck(!item.isCheck());
            }
        });
    }

}
